package com.wheatek.navigation

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.navigation.Navigation


/**
 */
class Fragment2 : Fragment() {

    var mName = ""

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            mName = it.getString("name")
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_2, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.findViewById<TextView>(R.id.tvName).text = mName

        view.findViewById<Button>(R.id.btnPreview).setOnClickListener {
            Navigation.findNavController(view).popBackStack()
        }

        view.findViewById<Button>(R.id.btnNext).setOnClickListener {
            Navigation.findNavController(view).navigate(R.id.action_fragment2_to_fragment3)
        }
    }
}